#! /bin/bash
##############
# - 红帽系
##############
yum install -y yum-utils device-mapper-persistent-data lvm2

# 上传安装包
# docker-ce
# containerd.io
# docker-ce-cli
# docker-compose-plugin
yum localinstall ./*.rpm

##############
# - deiban系
##############
source /etc/os-release
cat <<EOF > /etc/apt/sources.list.d/docker.list
deb [arch=arm64 signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.ustc.edu.cn/docker-ce/linux/${ID} $VERSION_CODENAME stable
EOF
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
apt clean all
apt update
apt-get install lvm2 thin-provisioning-tools
apt-get install ca-certificates curl gnupg
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

##############
# - 通用部分
##############
# cat <<EOF > /etc/docker/daemon.json
# {
#     "registry-mirrors": [
#         "https://docker.1ms.run",
#         "https://docker.xuanyuan.me"
#     ]
# }
# EOF

cat <<EOF > /etc/docker/daemon.json
{
    "registry-mirrors": [
      "https://docker.m.daocloud.io"
    ],
    "live-restore": true
  }
EOF

cat <<EOF > /etc/rancher/k3s/registries.yaml
mirrors:
  "docker.io":
    endpoint:
      - "https://docker.m.daocloud.io"  # 你原有的 Docker Hub 加速镜像
      - "https://registry-1.docker.io"  # 官方地址作为备用，增强可靠性
configs: # 通常情况下，公共仓库无需认证，此部分可省略，保留结构以备不时之需
EOF

systemctl start docker
docker pull hello-world
docker images

##############
# - 红帽系
##############
systemctl disable firewalld && 
systemctl stop firewalld && 
setenforce 0

cat <<EOF > /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
EOF
##############
# - debian系
##############
systemctl disable ufw
systemctl stop ufw
systemctl disable apparmor
systemctl stop apparmor

##############
# - 通用部分
##############
curl -sfL https://rancher-mirror.rancher.cn/k3s/k3s-install.sh | INSTALL_K3S_SKIP_SELINUX_RPM=true INSTALL_K3S_MIRROR=cn sh -
ln -s /usr/local/bin/k3s /usr/bin/kubectl
kubectl get nodes